<template>
	<view class="pop-content">
		<view class="title-row">
			邀请好友
		</view>
		<view class="list-view">
			<button type="default" open-type="share">
				<image src="../../static/invite_img/wechat.svg" style="height: 40px; width: 40px;"></image>
				微信
			</button>
			<button type="default" @click="gotoPhoneInvite">
				<image src="../../static/invite_img/phone.svg" style="height: 40px; width: 40px;"></image>
				手机
			</button>
			<button type="default" @click="codeInvite">
				<image src="../../static/invite_img/code.svg" style="height: 40px; width: 40px;"></image>
				二维码
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-share-pop",
		props: {
			fridge: {
				type: Object
			}
		},
		data() {
			return {

			};
		},
		methods: {
			async codeInvite() {
				await uni.$api.fridge.getQrCode(this.fridge.fid).then((uri) => {
					console.log(uni.$downloadPath + uri);
					wx.downloadFile({
						url: uni.$downloadPath + uri,
						success: (res) => {
							console.log(res.tempFilePath);
							if (res.dataLength < 1000) {
								uni.$showMsg('后台申请的冰箱二维码异常')
							}
							wx.showShareImageMenu({
								path: res.tempFilePath,
								success: (res) => {
									console.log("success:" + res.errMsg);
								},
								fail: (err) => {
									console.log("err:" + err.errMsg);
								}
							})
							this.close()
						},
						fail: () => {
							console.log("获取冰箱二维码失败");
						}
					})
				})
			},
			gotoPhoneInvite() {
				// return uni.$showMsg('现阶段仅体验用户可用')
				uni.navigateTo({
					url: '/pagesSub/pageUser/phone_invite/phone_invite?fid=' + this.fridge.fid
				})
				this.close()
			},
			close() {
				this.$emit('close')
			}
		}
	}
</script>

<style lang="scss">
	.pop-content {
		display: flex;
		flex-direction: column;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		align-items: center;
		padding: 10px;

		.title-row {
			font-size: 22px;
			padding-bottom: 20rpx;
		}

		.list-view {
			display: flex;
			justify-content: space-evenly;
			width: 80%;

			>button {
				width: 20%;
				background-color: #fff;
				overflow: unset;
				box-sizing: unset;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				font-size: 16px;
			}

			>button::after {
				border: none;
			}
		}
	}
</style>